<template>
  <div ref="echart" class="echart"></div>
</template>

<script>
export default {
  data() {
    return {
      echart: null
    }
  },
  mounted() {
    this.initDta()
  },
  methods: {
    initDta() {
      this.echart = this.$echarts.init(this.$refs.echart)
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985',
            },
          },
          formatter: function (params) {
            var relVal = params[0].name
            for (var i = 0, l = params.length; i < l; i++) {
              relVal += '<br/>' + params[i].marker + params[i].value + '万艘次'
            }
            return relVal
          },
        },
        legend: {
          show: false,
          top: '0%',
          right: '5%',
          icon: 'rect',
          textStyle: {
            color: '#FFF',
            fontSize: 14,
          },
          itemStyle: {
            borderType: 'solid',
          },
        },
        grid: {
          top: '8%',
          left: '6%',
          right: '6%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            axisLabel: {
              color: '#fff',
              fontSize: 14,
            },
            data: ['2019年', '2020年','2021年','2022年','2023年'],
          },
        ],
        yAxis: {
          axisLabel: {
            show: false,
          },
          splitLine: {
            lineStyle: {
              color: '#2a3961',
            },
          },
          axisTick: {
            show: false,
          },
        },
        series: [
          {
            name: '整体船舶数量',
            type: 'line',
            smooth: true,
            itemStyle: {
              color: '#F5BC28',
            },
            areaStyle: {
              color: this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
                {
                  offset: 0,
                  color: '#FFDA78',
                },
                {
                  offset: 1,
                  color: 'rgba(255, 207, 78, 0)',
                },
              ]),
            },
            data: [30, 32,30,38,17],
          },
        ],
      }
      this.echart.setOption(option)
    }
  }
}
</script>

<style scoped lang="less">
.echart {
  width: 100%;
  height: 100%;
}
</style>
